﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Logistics.DAL
{
    public class TruckTeamDAL
    {
        public static List<Model.TruckTeam> GetTruckTeams()
        {
            string sql = "select top 3 * from TruckTeam where IsDelete=0";
            SqlDataReader reader = SqlHelper.ExecuteReader(sql, null);
            return TruckTeamList(reader);
        }
        public static Model.TruckTeam Eshow(string TeamID) 
        {
            string sql = "select * from TruckTeam where TeamID=@TeamID";
            SqlParameter[] pms = new SqlParameter[] {
                new SqlParameter("@TeamID",TeamID)
            };
            SqlDataReader reader= SqlHelper.ExecuteReader(sql,pms);
            return TruckTeamList(reader)[0];
        }
        public static List<Model.TruckTeam> TruckTeamList(SqlDataReader reader) 
        {
            List<Model.TruckTeam> lst = new List<Model.TruckTeam>();
            while (reader.Read())
            {
                Model.TruckTeam t = new Model.TruckTeam();
                t.TeamID = Convert.ToInt32(reader["TeamID"]);
                t.TeamName = reader["TeamName"].ToString();
                t.Leader = reader["Leader"].ToString();
                t.Remark = reader["Remark"].ToString();
                t.CheckInTime = reader["CheckInTime"].ToString();
                t.IsDelete = Convert.ToInt32(reader["TeamID"]);
                t.AlterTime = reader["AlterTime"].ToString();
                lst.Add(t);
            }
            reader.Close();
            return lst;
        }
        public static int Del(string TeamID)
        {
            string sql = "update TruckTeam set IsDelete=1 where TeamID=@TeamID";
            SqlParameter[] pms = new SqlParameter[]
            {
                new SqlParameter("@TeamID",TeamID)
            };
            return SqlHelper.ExecuteNonQuery(sql, pms);
        }
        public static int updatetruckteam(string TeamName, string Leader, string TeamID)
        {
            string sql = "update TruckTeam set TeamName=@TeamName,Leader=@Leader where TeamID=@TeamID";
            SqlParameter[] pms = new SqlParameter[]
            {
                new SqlParameter("@TeamName",TeamName),
                new SqlParameter("@Leader",Leader),
                new SqlParameter("@TeamID",TeamID)
            };
            return SqlHelper.ExecuteNonQuery(sql, pms);
        }
    }
}
